package com.doubletick.proxy.ipidea.controller;

import com.doubletick.common.annotation.Log;
import com.doubletick.common.core.controller.BaseController;
import com.doubletick.common.core.domain.AjaxResult;
import com.doubletick.common.core.page.TableDataInfo;
import com.doubletick.common.enums.BusinessType;
import com.doubletick.common.utils.poi.ExcelUtil;
import com.doubletick.proxy.ipidea.domain.ProxyAccountFlow;
import com.doubletick.proxy.ipidea.service.IProxyAccountFlowService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代理账号流量Controller
 *
 * @author ruoyi
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/proxy/flow")
public class ProxyAccountFlowController extends BaseController {
    @Autowired
    private IProxyAccountFlowService proxyAccountFlowService;

    /**
     * 查询代理账号流量列表
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProxyAccountFlow proxyAccountFlow) {
        startPage();
        List<ProxyAccountFlow> list = proxyAccountFlowService.selectProxyAccountFlowList(proxyAccountFlow);
        Object summary = proxyAccountFlowService.summary(proxyAccountFlow);
        return getDataTable(list, summary);
    }


    /**
     * 导出代理账号流量列表
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:export')")
    @Log(title = "代理账号流量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProxyAccountFlow proxyAccountFlow) {
        List<ProxyAccountFlow> list = proxyAccountFlowService.selectProxyAccountFlowList(proxyAccountFlow);
        ExcelUtil<ProxyAccountFlow> util = new ExcelUtil<ProxyAccountFlow>(ProxyAccountFlow.class);
        util.exportExcel(response, list, "代理账号流量数据");
    }


    /**
     * 查询代理账号流量列表
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:listByDay')")
    @GetMapping("/listByDay")
    public TableDataInfo listByDay(ProxyAccountFlow proxyAccountFlow) {
        startPage();
        List<ProxyAccountFlow> list = proxyAccountFlowService.selectProxyAccountFlowListByDay(proxyAccountFlow);
        Object summary = proxyAccountFlowService.summary(proxyAccountFlow);
        return getDataTable(list, summary);
    }


    @PreAuthorize("@ss.hasPermi('proxy:flow:exportByDay')")
    @Log(title = "代理账号流量", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByDay")
    public void exportByDay(HttpServletResponse response, ProxyAccountFlow proxyAccountFlow) {
        List<ProxyAccountFlow> list = proxyAccountFlowService.selectProxyAccountFlowListByDay(proxyAccountFlow);
        ExcelUtil<ProxyAccountFlow> util = new ExcelUtil<ProxyAccountFlow>(ProxyAccountFlow.class);
        util.exportExcel(response, list, "代理账号流量数据");
    }

    /**
     * 获取代理账号流量详细信息
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(proxyAccountFlowService.selectProxyAccountFlowById(id));
    }

    /**
     * 新增代理账号流量
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:add')")
    @Log(title = "代理账号流量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProxyAccountFlow proxyAccountFlow) {
        return toAjax(proxyAccountFlowService.insertProxyAccountFlow(proxyAccountFlow));
    }

    /**
     * 修改代理账号流量
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:edit')")
    @Log(title = "代理账号流量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProxyAccountFlow proxyAccountFlow) {
        return toAjax(proxyAccountFlowService.updateProxyAccountFlow(proxyAccountFlow));
    }

    /**
     * 删除代理账号流量
     */
    @PreAuthorize("@ss.hasPermi('proxy:flow:remove')")
    @Log(title = "代理账号流量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(proxyAccountFlowService.deleteProxyAccountFlowByIds(ids));
    }
}
